<?
	function generate_xml_from_array($array, $node_name) {

		if (is_array($array) || is_object($array)) {
			foreach ($array as $key=>$value) {
				if (is_numeric($key)) {
					$key = $node_name;
				}
				$xml .= '<' . $key . '>' . "\n" . generate_xml_from_array($value, $node_name) . '</' . $key . '>' . "\n";
			}
		} else {
			$xml = htmlspecialchars($array, ENT_QUOTES) . "\n";
		}

		return $xml;
	}

	function array2xml($array, $header='<?xml version="1.0" encoding="UTF-8" ?>') {
		$xml = $header . "\n";

		$xml .= generate_xml_from_array($array, "");

		return $xml;
	}
	
	function print_output($array) {
		echo isset($_REQUEST['xml']) && $_REQUEST['xml'] != 0 ? 
			array2xml($array) : " " . json_encode($array);
	}
?>